<template>
	<view class="container">
		<!-- 用户信息卡片 -->
		<view class="user-card">
			<view class="user-header">
				<image class="bg-image" src="https://images.unsplash.com/photo-1579546929518-9e396f3cc809?ixlib=rb-1.2.1&auto=format&fit=crop&w=750&q=80"></image>
				<view class="user-avatar-container">
					<image class="user-avatar" src="https://images.unsplash.com/photo-1494790108377-be9c29b29330"></image>
				</view>
			</view>
			<view class="user-details">
				<view class="user-name-row">
					<text class="user-name">{{ userInfo.username }}</text>
					<view class="edit-profile-btn" @tap="editProfile">
						<text class="edit-text">编辑资料</text>
					</view>
				</view>
				<text class="user-id">ID: {{ userInfo.userId }}</text>

				<view class="user-stats">
					<view class="stat-item" @tap="navigateTo('/pages/favorites/favorites')">
						<text class="stat-value">{{ userInfo.favorites }}</text>
						<text class="stat-label">收藏</text>
					</view>
					<view class="stat-divider"></view>
					<view class="stat-item" @tap="navigateTo('/pages/orders/orders')">
						<text class="stat-value">{{ userInfo.orders }}</text>
						<text class="stat-label">订单</text>
					</view>
					<view class="stat-divider"></view>
					<view class="stat-item" @tap="navigateTo('/pages/reviews/reviews')">
						<text class="stat-value">{{ userInfo.reviews }}</text>
						<text class="stat-label">评价</text>
					</view>
				</view>
			</view>
		</view>

		<!-- 我的服务 -->
		<view class="section-title">我的服务</view>
		<view class="menu-grid">
			<view class="grid-item" @tap="navigateTo('/pages/orders/orders')">
				<view class="grid-icon">📷</view>
				<text class="grid-text">我的预约</text>
			</view>
			<view class="grid-item" @tap="navigateTo('/pages/photos/photos')">
				<view class="grid-icon">🖼️</view>
				<text class="grid-text">我的照片</text>
			</view>
			<view class="grid-item" @tap="navigateTo('/pages/favorites/favorites')">
				<view class="grid-icon">❤️</view>
				<text class="grid-text">我的收藏</text>
			</view>
			<view class="grid-item" @tap="navigateTo('/pages/reviews/reviews')">
				<view class="grid-icon">📝</view>
				<text class="grid-text">我的评价</text>
			</view>
		</view>

		<!-- 功能菜单 -->
		<view class="section-title">设置与帮助</view>
		<view class="menu-section">
			<view class="menu-item" @tap="navigateTo('/pages/settings/settings')">
				<view class="menu-icon">⚙️</view>
				<text class="menu-text">设置</text>
				<text class="menu-arrow">›</text>
			</view>
			<view class="menu-item" @tap="contactService">
				<view class="menu-icon">📞</view>
				<text class="menu-text">联系客服</text>
				<text class="menu-arrow">›</text>
			</view>
			<view class="menu-item" @tap="navigateTo('/pages/help/help')">
				<view class="menu-icon">❓</view>
				<text class="menu-text">帮助中心</text>
				<text class="menu-arrow">›</text>
			</view>
			<view class="menu-item" @tap="navigateTo('/pages/about/about')">
				<view class="menu-icon">ℹ️</view>
				<text class="menu-text">关于我们</text>
				<text class="menu-arrow">›</text>
			</view>
		</view>

		<!-- 退出登录 -->
		<view class="logout-btn" @tap="logout">
			<text>退出登录</text>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			userInfo: {
				username: '用户名',
				userId: '12345678',
				avatar: 'https://images.unsplash.com/photo-1494790108377-be9c29b29330',
				favorites: 12,
				orders: 8,
				reviews: 5
			}
		};
	},
	methods: {
		editProfile() {
			// 跳转到编辑资料页面
			uni.navigateTo({
				url: '/pages/profile/edit'
			});
		},
		navigateTo(url) {
			// 修改导航方法，确保路径正确
			try {
				// 检查是否是tabbar页面
				const tabbarPages = ['/pages/home/home', '/pages/profile/profile', '/pages/orders/orders'];

				if (tabbarPages.includes(url)) {
					// 如果是tabbar页面，使用switchTab
					uni.switchTab({
						url: url
					});
				} else {
					// 其他页面使用navigateTo
					uni.navigateTo({
						url: url
					});
				}
			} catch (e) {
				console.error('导航错误', e);
				uni.showToast({
					title: '页面跳转失败',
					icon: 'none'
				});
			}
		},
		contactService() {
			// 联系客服
			uni.showModal({
				title: '联系客服',
				content: '客服电话：400-123-4567\n工作时间：9:00-18:00',
				showCancel: false
			});
		},
		logout() {
			// 退出登录确认
			uni.showModal({
				title: '提示',
				content: '确定要退出登录吗？',
				success: (res) => {
					if (res.confirm) {
						// 执行退出登录
						uni.showToast({
							title: '已退出登录',
							icon: 'success'
						});

						// 跳转到登录页
						setTimeout(() => {
							uni.reLaunch({
								url: '/pages/login/login'
							});
						}, 1500);
					}
				}
			});
		}
	}
};
</script>

<style>
.container {
	padding: 30rpx;
	background-color: #f5f5f5;
	min-height: 100vh;
}

/* 用户卡片样式 */
.user-card {
	background-color: #fff;
	border-radius: 20rpx;
	overflow: hidden;
	box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.05);
	margin-bottom: 30rpx;
}

.user-header {
	position: relative;
	height: 200rpx;
}

.bg-image {
	width: 100%;
	height: 100%;
	position: absolute;
	top: 0;
	left: 0;
}

.user-avatar-container {
	position: absolute;
	bottom: -60rpx;
	left: 40rpx;
	padding: 6rpx;
	background-color: #fff;
	border-radius: 50%;
}

.user-avatar {
	width: 120rpx;
	height: 120rpx;
	border-radius: 50%;
}

.user-details {
	padding: 70rpx 40rpx 30rpx;
}

.user-name-row {
	display: flex;
	justify-content: space-between;
	align-items: center;
	margin-bottom: 10rpx;
}

.user-name {
	font-size: 36rpx;
	font-weight: bold;
	color: #333;
}

.edit-profile-btn {
	padding: 10rpx 24rpx;
	background-color: #f3f4f6;
	border-radius: 30rpx;
}

.edit-text {
	font-size: 24rpx;
	color: #666;
}

.user-id {
	font-size: 24rpx;
	color: #999;
	margin-bottom: 30rpx;
}

.user-stats {
	display: flex;
	justify-content: space-around;
	padding-top: 20rpx;
	border-top: 1rpx solid #f3f4f6;
}

.stat-item {
	display: flex;
	flex-direction: column;
	align-items: center;
}

.stat-value {
	font-size: 32rpx;
	font-weight: bold;
	color: #333;
}

.stat-label {
	font-size: 24rpx;
	color: #999;
	margin-top: 6rpx;
}

.stat-divider {
	width: 1rpx;
	height: 40rpx;
	background-color: #eaeaea;
	margin-top: 10rpx;
}

/* 网格菜单 */
.section-title {
	font-size: 30rpx;
	font-weight: bold;
	color: #333;
	margin: 30rpx 0 20rpx;
}

.menu-grid {
	display: flex;
	flex-wrap: wrap;
	background-color: #fff;
	border-radius: 20rpx;
	padding: 20rpx;
	box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.05);
	margin-bottom: 30rpx;
}

.grid-item {
	width: 25%;
	display: flex;
	flex-direction: column;
	align-items: center;
	padding: 20rpx 0;
}

.grid-icon {
	font-size: 50rpx;
	margin-bottom: 10rpx;
}

.grid-text {
	font-size: 24rpx;
	color: #666;
}

/* 列表菜单 */
.menu-section {
	background-color: #fff;
	border-radius: 20rpx;
	overflow: hidden;
	box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.05);
	margin-bottom: 30rpx;
}

.menu-item {
	display: flex;
	align-items: center;
	padding: 30rpx;
	border-bottom: 1rpx solid #f3f4f6;
}

.menu-item:last-child {
	border-bottom: none;
}

.menu-icon {
	width: 50rpx;
	font-size: 36rpx;
	margin-right: 20rpx;
}

.menu-text {
	flex: 1;
	font-size: 28rpx;
	color: #333;
}

.menu-arrow {
	font-size: 32rpx;
	color: #cccccc;
}

/* 退出登录按钮 */
.logout-btn {
	background-color: #fff;
	border-radius: 20rpx;
	padding: 30rpx;
	text-align: center;
	color: #ff4d4f;
	font-size: 30rpx;
	font-weight: 500;
	box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.05);
}
</style>
